home *** CD-ROM | disk | FTP | other *** search
- function createCard(n, w, h)
- {
- empty.push(n);
- this.createEmptyMovieClip("card" + n,n);
- with(this["card" + n])
- {
- lineStyle(0,0,100);
- beginFill(153,60);
- moveTo(w / 2,0);
- lineTo(w / 2,h / 2);
- lineTo((- w) / 2,h / 2);
- lineTo((- w) / 2,(- h) / 2);
- lineTo(w / 2,(- h) / 2);
- lineTo(w / 2,0);
- endFill();
- createEmptyMovieClip("back",1);
- back.loadMovie("cards/card_back.jpg");
- back._x = 2 - w / 2;
- back._y = 2 - h / 2;
- createEmptyMovieClip("front",2);
- front.createEmptyMovieClip("container",3);
- front.createEmptyMovieClip("backgr",2);
- with(front.backgr)
- {
- moveTo((- w) / 2,(- h) / 2);
- lineStyle(0,0,0);
- beginFill(3355443,100);
- lineTo(w / 2,(- h) / 2);
- lineTo(w / 2,h / 2);
- lineTo((- w) / 2,h / 2);
- lineTo((- w) / 2,(- h) / 2);
- endFill();
- }
- front.onEnterFrame = function()
- {
- tot = this.container.getBytesTotal();
- car = this.container.getBytesLoaded();
- if(tot == car && tot > 200)
- {
- this._parent._parent.centerImage(this._parent);
- delete this.onEnterFrame;
- }
- };
- }
- }
- function placeImages()
- {
- act_img = 1;
- img = 0;
- while(img < imgs_n)
- {
- k = 0;
- while(k < 2)
- {
- act = Math.round(Math.random() * (empty.length - 1));
- this["card" + empty[act]].img_id = act_img;
- this["card" + empty[act]].front.container.loadMovie("cards/card_img" + act_img + ".jpg");
- this["card" + empty[act]].onRelease = function()
- {
- this.rotateCard(0,0);
- this.enabled = false;
- MovieClip.prototype.enabled = false;
- };
- empty.splice(act,1);
- k++;
- }
- act_img++;
- img++;
- }
- }
- function generateGameField(cards, distance, hdistance)
- {
- Ypos = card_h / 2 + hdistance;
- Xpos = card_w / 2 + distance;
- c = 0;
- while(c < cards)
- {
- createCard(c,card_w,card_h);
- if(c % row_card == 0 && c > 0)
- {
- Ypos += this["card" + c]._height + hdistance;
- Xpos = card_w / 2 + distance;
- }
- this["card" + c]._x = Xpos;
- this["card" + c]._y = Ypos;
- Xpos += this["card" + c]._width + distance;
- c++;
- }
- placeImages();
- score = 0;
- turns = 0;
- score_txt = "0";
- }
- function checkCards()
- {
- if(this[selcards[0]].img_id == this[selcards[1]].img_id)
- {
- score++;
- eval(selcards[0])._visible = eval(selcards[1])._visible = false;
- }
- else
- {
- eval(selcards[0]).rotateCard(1,1);
- eval(selcards[1]).rotateCard(1,1);
- eval(selcards[0]).enabled = eval(selcards[1]).enabled = true;
- }
- if(score == 25)
- {
- play();
- }
- turns++;
- score_txt = turns;
- selcards = [];
- MovieClip.prototype.enabled = true;
- }
- centerImage = function(target)
- {
- target.front._visible = false;
- target.front.container._x -= target.front.container._width / 2;
- target.front.container._y -= target.front.container._height / 2;
- };
- empty = new Array();
- selcards = [];
- MovieClip.prototype.rotateCard = function(v, i)
- {
- this.operazione = v != 0 ? -0.35 : 0.35;
- this.incremento = i != 0 ? 10 : 100;
- selcards.push(this._name);
- this.onEnterFrame = function()
- {
- this.incremento += this.operazione;
- this._xscale = 100 * Math.sin(this.incremento);
- if(this._xscale > 0)
- {
- this.front._visible = v != 1 ? true : false;
- }
- if(this._xscale >= 99)
- {
- delete this.onEnterFrame;
- selcards.length >= 2 ? null : (MovieClip.prototype.enabled = true);
- !(v == 0 && selcards.length > 1) ? null : checkCards();
- }
- };
- };
- generateGameField(n_card,card_wdistance,card_hdistance);
- stop();
-